﻿namespace Sai.Test.Sandcastle
{
	using Xunit;
	using Sai.Core.Sandcastle;
    using Sai.Test.XUnit;

	public class StringExtensionFacts
	{
		public class TheContainingFolderMethod
		{
			
			[Fact, InMemoryTest]
			public void Returns_Folder_For_File_Full_Path()
			{
				const string folder = "C:\\Dev\\Test";

				string filePath = System.IO.Path.Combine(folder, "myfile.txt");

				Assert.Equal(folder, filePath.ContainingFolder());
			}
		}

		public class TheRelativeToFolderMethod
		{
			
			[Fact, InMemoryTest]
			public void Returns_Relative_Path_For_File_Full_Path()
			{
				const string baseFolder = "C:\\Dev";
				const string fullPath = "C:\\Dev\\Test\\myfile.cs";

				Assert.Equal("Test\\myfile.cs", fullPath.RelativeToFolder(baseFolder));
			}

			
			[Fact, InMemoryTest]
			public void File_Full_Path_Round_Trips_Relative_And_Back()
			{
				const string baseFolder = "C:\\Dev";
				const string fullPath = "C:\\Dev\\Test\\myfile.cs";

				Assert.Equal(fullPath, fullPath.RelativeToFolder(baseFolder).AbsoluteFromFolder(baseFolder));
			}
		}

		public class TheAbsoluteFromFolderMethod
		{
			
			[Fact, InMemoryTest]
			public void Returns_Absolute_Path_For_File_Relative_Path()
			{
				const string baseFolder = "C:\\Dev";
				const string file = "Test\\myfile.cs";

				Assert.Equal("C:\\Dev\\Test\\myfile.cs", file.AbsoluteFromFolder(baseFolder));
			}
		}
	}
}
